package com.llf.Blog.ServiceImpl;

import com.llf.Blog.Pojo.Blog;
import com.llf.Blog.Mapper.BlogMapper;
import com.llf.Blog.Service.BlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.llf.Utils.MarkDownUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author llf
 * @since 2021-08-07
 */
@Transactional(rollbackFor=Exception.class)
@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {

    @Autowired
    private  BlogMapper blogMapper;

    @Override
    public List<Blog> getAllBlog(Integer typeId, String title,Boolean published) {
        return blogMapper.getAllBlog(typeId,title,published);
    }

    @Override
    public Boolean updateBlog(Blog blog) {
        return blogMapper.updateBlog(blog);
    }

    @Override
    public List<Blog> getBlog(Long id) {
        return blogMapper.getBlog(id);
    }

    @Override
    public List<Blog> getBlogByTime() {
        return blogMapper.getBlogByTime();
    }

    @Override
    public List<Blog> getBlogByLike(String quarry) {
        return blogMapper.getBlogByLike(quarry);
    }

    @Override
    public List<Blog> getBlogByTagId(Long id) {
        return blogMapper.getBlogByTagId(id);
    }

    @Override
    public List<Blog> getAllByYear(Integer year) {
        return blogMapper.getAllByYear(year);
    }

    /**
     *  将内容从text转换为MarkDown
     * @param id
     * @return
     */
    @Override
    public Blog getBlogById(Long id) {
        blogMapper.updateViews(id);
        Blog blog = blogMapper.getBlogById(id);
        String content=blog.getContent();
        blog.setContent(MarkDownUtils.markdownToHtmlExtensions(content));
        return blog;
    }




}
